function ajaxFileUpload(flag)
{
	$("#loading")
	.ajaxStart(function(){
		$(this).show();
	})
	.ajaxComplete(function(){
		$(this).hide();
	});
	var bbsCd = $("#bbsCd").val();
	var seq = 0;
	//alert(board_cd);
	var param = {bbsCd:bbsCd, seq:seq, flag:flag}
	$.ajaxFileUpload
	(
		{
			url:'/action/common/saveFileup.asp',
			secureuri:false,
			fileElementId:'uFile',
            //type: 'POST',
			dataType: 'json',
			data:param,
			success: function (data)
			{
				if(data.rsStatus == 'Success')
				{
					var imgSeq = data.Seq;
					alert(data.fileNm);
					/*
					if (imgSeq) $("#"+"IMGSEQ").val($("#"+"IMGSEQ").val()+imgSeq+",");
					if (data.type == "I") var showImg = "<img src=\""+fullFileNm+"\" width=\"100\" onClick=\"fnDelImg('"+imgSeq+"')\" style=\"margin-right:10px;cursor:hand;vertical-align:text-top;border:1px #999999 solid;\" alt=\"삭제를 원하시면 이미지를 클릭해주세요\">";
					else 
					{
						var vFileNm = fullFileNm.replace("/uploads/","");
						showImg = " [<a href=\""+fullFileNm+"\"> "+vFileNm+"</a> <a href=\"javascript:fnDelImg('"+imgSeq+"')\">[X]</a>]";
					}
					$("#"+"showUpFile").append(showImg);
					$("#"+"attaches").css("display","");
					*/
				}
				else
				{
					alert(data.rsStatus);
				}
			},
			error: function (data, rsStatus, e)
			{
				alert(e);
			}
		}
	)	
	return false;
}

function fnDelImg(imgSeq)
{	
	if(confirm("이 이미지를 정말로 삭제 하시겠습니까?")) 
	{
		var valUrl = "/azone/fileup/ajaxFileupDel.php";
		var param = "imgSeq="+imgSeq;
		$.ajax({
			url: valUrl,
			type: 'POST',
			dataType: 'json',
			data: param,
			success: function(data){
				alert(data.rsStatus);				
				fnImgList();
			},
			error: function(data){
				alert('Error!!\r\n'+data.rsStatus);
			}
		});
	}
}

function fnImgList()
{	
	var imgSeqs = $("#"+"IMGSEQ").val();
	if (imgSeqs.substr(0,1) == ",")
	{
		imgSeqs = imgSeqs.substr(1,imgSeqs.length);
	}
	var valUrl = "/azone/fileup/ajaxFileupList.php";
	//var param = "imgSeqs="+imgSeqs;
	var param = "board_cd="+$("#BOARD_CD").val();
		param += "&bid="+$("#BID").val();

	$.ajax({
		url: valUrl,
		type: 'POST',
		dataType: 'json',
		data: param,
		success: function(data){
			var imgCnt = data.TOTAL_ROW_COUNT;
	        var imgList = data.IMG;
	        var showImg = "";
	        var showFile = "첨부파일 : ";
	        var imgSeqs = "";
	        $("#"+"showUpFile").html("");
	        for(var t=0; t<imgCnt; t++)
	        {   
	        	var fullFileNm = imgList[t].IMG_URL;
	        	var imgSeq = imgList[t].IMGSEQ;
	        	if (imgSeqs) imgSeqs += ",";
	        	imgSeqs += imgList[t].IMGSEQ;
	        	if (imgList[t].TYPE == "I")
	        	{
	        		showImg += "<img src=\""+fullFileNm+"\" width=\"100\" onClick=\"fnDelImg('"+imgSeq+"')\" style=\"margin-right:10px;cursor:hand;vertical-align:text-top;border:1px #999999 solid;\" alt=\"삭제를 원하시면 이미지를 클릭해주세요\">";
	        	}
	        	else
	        	{
	        		var vFileNm = fullFileNm.replace("/uploads/","");
	        		showFile += " [<a href=\""+fullFileNm+"\"> "+vFileNm+"</a> <a href=\"javascript:fnDelImg('"+imgSeq+"')\">[X]</a>]";
	        	}
	        }
	        $("#"+"showUpFile").append(showFile+"<br>"+showImg);
			$("#"+"attaches").css("display","");
			$("#"+"IMGSEQ").val(imgSeqs);
		},
		error: function(data){
			alert('Error!!\r\n'+data);
		}
	});
}

function fnSetMain(imgSeq)
{
	var valUrl = "/azone/fileup/ajaxFileupSetMain.php";
	var param = "imgSeq="+imgSeq;
		param += "&board_id=<?=$board_dbname?>";
		param += "&board_uid=<?=$board_uid?>";
	//window.open(varUrl+"?"+param);
	$.ajax({
		url: valUrl,
		type: 'POST',
		dataType: 'xml',
		data: param,
		success: function(xml){
			fnImgList();
		},
		error: function(xml){
			alert('Error!!\r\n'+xml.responseText);
		}
	});

}